/**
* TODO
* @Project: topcrazy
* @Title: CommonController.java
* @Package net.topcrazy.blog.controller.sys
* @author notepad
* @Date Sep 24, 2012 9:15:49 PM
* @Copyright: 2012 www.topcrazy.net
* @Version v1.0.0
*/
package net.topcrazy.blog.controller.sys;

import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.topcrazy.base.util.validatecode.ValidateCodeCreator;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * TODO
 * @ClassName: CommonController
 * @author notepad
 */
@Controller
@RequestMapping("/common")
public class CommonController
{
	@RequestMapping(value="/validateCode")
	public void validateCode(HttpServletRequest request,HttpServletResponse response){
//		/**
//		 * 页面属性设置
//		 */
        response.setContentType("image/jpeg");    
        response.setHeader("Pragma", "No-cache");    
        response.setHeader("Cache-Control", "no-cache");    
        response.setDateHeader("Expires", 0);
        
        try {    
        	/**
        	 * 生成图象与验证码
        	 */
            ValidateCodeCreator validateCodeCreator = new ValidateCodeCreator();    
            BufferedImage img = validateCodeCreator.creatImageAndCode();    
            
            request.getSession().setAttribute("validateCode", validateCodeCreator.getValidateCode());
            
            ImageIO.write(img, "JPEG", response.getOutputStream());    
            response.getOutputStream().flush();    
            response.getOutputStream().close();    
            
        } catch (Exception e) {    
        }
	}

}
